package edu.uoc.tdp.pac3.server.impl;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.List;

import edu.uoc.tdp.pac3.beans.Resource;
import edu.uoc.tdp.pac3.beans.ResourceRequest;
import edu.uoc.tdp.pac3.beans.Room;
import edu.uoc.tdp.pac3.common.StockManagerInterface;
import edu.uoc.tdp.pac3.manager.GenericManager;

public class StockManagerImpl extends java.rmi.server.UnicastRemoteObject
		implements StockManagerInterface, Serializable {

	private static final long serialVersionUID = 1L;

	public StockManagerImpl() throws RemoteException {
		super();
	}

	public StockManagerImpl(int port) throws RemoteException {
		super(port);
	}

	public String test() throws RemoteException {
		System.out.println("test()");
		return new String("Hello World with RMI!");
	}
	
	public void addNewStock(String resourceName, int newQuantity) throws RemoteException {
		GenericManager.addNewStock(resourceName, newQuantity);
	}
	
	public int addResourceRequest(String nomAula, String nomRecurs, int quant) throws RemoteException {
		return GenericManager.addResourceRequest(nomAula, nomRecurs, quant);
	}
	
	public void updateStock(int idRecurs, int quant) throws RemoteException{
		GenericManager.updateStock(idRecurs, quant);
	}
	
	// Methods to fill the client comboBoxes:
	public List<Resource> getAllResources() throws RemoteException {
		return GenericManager.getAllResources();
	}
	
	public List<Room> getAllRooms() throws RemoteException {
		return GenericManager.getAllRooms();
	}
	
	//Methods to fill the tables 
	public List<ResourceRequest> getAllResourceRequests() throws RemoteException{
		
		return GenericManager.getAllResourceRequests();
	}
	
	public List<ResourceRequest> getNoPossibleRequests() throws RemoteException{
		return GenericManager.getNoPossibleRequests();
	}
	
	public void finalizeResourceRequest(int quantToDelete, int idResource, int idRoom) throws Exception{
		GenericManager.finalizeResourceRequest(quantToDelete, idResource, idRoom);
	}
	
	public String loadRoomNameById(int roomId) throws Exception{
		return GenericManager.loadRoomNameById(roomId);
	}
	
	public String loadResourceNameById(int idResource) throws Exception{
		return GenericManager.loadResourceNameById(idResource);
	}
	
}